window.onload=function(){
	Connect();
	var socket;
	function Connect(){
		try{
			socket = new WebSocket('ws://127.0.0.1:9000');
		}catch(e){
			alert('error new WebSocket');
			return;
		}
		socket.onopen = sOpen;
		socket.onerror = sError;
		socket.onmessage = sMessage;
		socket.onclose = sClose;
	}
	function sOpen(){
		var msgbody = '服务器连接成功';
		conModalMsg_show('服务器连接状态', msgbody);
	}
	function sError(){
		var msgbody = '服务器异常Error=' + e + '请检查';
		conModalMsg_show('服务器连接状态', msgbody);
	}
	function sMessage(msg){
		// alert('server says:' + msg.data);
		//由JSON字符串转换为JSON对象
		// vmOne.sites = JSON.parse(msg.data);
		parseMessageJson(msg.data);
	}
	function sClose(e){
		var msgbody = '服务器连接关闭ErrorCode=' + e.code;
		conModalMsg_show('服务器连接状态', msgbody);
	}
	function sSend(msg){
		socket.send(msg);
	}
	function conModalMsg_show(title,msgbody){
		vmTwo.modalMsgTitle = title;
		vmTwo.modalMsgBody = msgbody;
		$('#conModal').modal('show');
	}
	function parseMessageJson(data){
		//由JSON字符串转换为JSON对象
		var msg = JSON.parse(data);
		if("queryUserServiceCfg" == msg.cmd){
			vmOne.sites = msg.data;
		}
		else if("saveUserServiceCfg" == msg.cmd){
			conModalMsg_show('数据保存状态', msg.data);
		}
	}

	var vmOne = new Vue({
		el: '#app',
		data:{
			message:"hello wor111ld!",
			sites: [
				// {userType:1,userDesc:'酒店高层',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pPublicity:false,pAdvisory:true,pDirecting:true,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:false},
				// {userType:2,userDesc:'参会人1',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pPublicity:false,pAdvisory:true,pDirecting:true,pStatistics:true,experience2:true,mSign:false,mPublicity:true,mAdvisory:true,mDirecting:false,mStatistics:false,mSameOne:false},
				// {userType:3,userDesc:'时间证人',hotelAdvertising:true,experience1:true,pSign:'无签到模块',pSignVipRite:false,pPublicity:true,pAdvisory:true,pDirecting:false,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:false},
				// {userType:4,userDesc:'赏金猎人',hotelAdvertising:false,experience1:false,pSign:'无签到模块',pSignVipRite:true,pPublicity:false,pAdvisory:false,pDirecting:true,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:true},
				// {userType:5,userDesc:'狗日的',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pSignFull:false,pSigndeltphoto:false,pSignPhone:true,pSignSimple:false,pPublicity:true,pAdvisory:true,pDirecting:true,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:true,mStatistics:false,mSameOne:false},
				// {userType:6,userDesc:'黑烟游侠',hotelAdvertising:false,experience1:false,pSign:'无签到模块',pSignVipRite:true,pSignFull:true,pSigndeltphoto:false,pSignPhone:false,pSignSimple:true,pPublicity:false,pAdvisory:false,pDirecting:true,pStatistics:true,experience2:true,mSign:false,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:true},
				// {userType:7,userDesc:'骷髅',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pSignFull:true,pSigndeltphoto:false,pSignPhone:true,pSignSimple:false,pPublicity:false,pAdvisory:true,pDirecting:true,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:true},
				// {userType:8,userDesc:'世界狂人',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pSignFull:true,pSigndeltphoto:false,pSignPhone:false,pSignSimple:true,pPublicity:false,pAdvisory:false,pDirecting:true,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:false},
				// {userType:9,userDesc:'潮汐猎人',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pSignFull:true,pSigndeltphoto:false,pSignPhone:true,pSignSimple:false,pPublicity:false,pAdvisory:true,pDirecting:false,pStatistics:true,experience2:true,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:false},
				// {userType:10,userDesc:'陌生人',hotelAdvertising:true,experience1:false,pSign:'无签到模块',pSignVipRite:true,pPublicity:false,pAdvisory:true,pDirecting:true,pStatistics:true,experience2:false,mSign:true,mPublicity:false,mAdvisory:true,mDirecting:false,mStatistics:true,mSameOne:false}
			]
		},
		methods: {
			queryBaseCfg: function(){
				var data={};
			},
			queryUserServiceCfg: function(){
				var data = {};
				data.cmd = 'queryUserServiceCfg';
				//将JSON对象转化为JSON字符然后发送
				sSend(JSON.stringify(data));
			},
			saveUserServiceCfg: function(){
				var data = {};
				data.cmd = 'saveUserServiceCfg';
				data.data = vmOne.sites;
				//将JSON对象转化为JSON字符然后发送
				sSend(JSON.stringify(data));
			},
			querysignInCfg: function(){
				var data={};
			},
			querypublicityCfg: function(){
				var data={};
			},
			queryadvisoryCfg: function(){
				var data={};
			},
			querydirectingCfg: function(){
				var data={};
			},
			querystatisticsCfg: function(){
				var data={};
			}
		}
	});

	var vmTwo = new Vue({
		el: '#conModal',
		data:{
			modalMsgTitle:'',
			modalMsgBody:''
		}
	});
}